
import pygame, pygame.font, pygame.event, pygame.draw, string
from pygame.locals import *
from Player import *
import sys

class box:


  def get_key(self):
    while 1:
      event = pygame.event.poll()
      if event.type == KEYDOWN:
        return event.key
      else:
        pass

  def display_box(self,screen, message):
    "Print a message in a box in the middle of the screen"
    #carregando o imgaem de teste
    #logo = pygame.image.load("python.png")
    fontobject = pygame.font.Font(None,24)
    pygame.draw.rect(screen, (0,0,0),((screen.get_width() / 2)+ 20 ,(screen.get_height() / 2) + 2, 260,20), 0)
    pygame.draw.rect(screen, (255,255,255),((screen.get_width() / 2) + 18,(screen.get_height() / 2), 264,24), 1)
    #########desenhado a cobra
    
        
    
    if len(message) != 0:
      #screen.blit(logo(400,400))
      screen.blit(fontobject.render(message, 1, (255,255,255)),((screen.get_width() / 2) - 100, (screen.get_height() / 2)))
      
      pygame.display.flip()

  def ask(self,screen, question):
    "ask(screen, question) -> answer"
    pygame.font.init()
    current_string = []
    self.display_box(screen, question+ string.join(current_string,""))
    
    
    while 1:
      inkey = self.get_key()
      #########apagando a palavra
      if inkey == K_BACKSPACE:
        current_string = current_string[0:-1]
      elif inkey == K_RETURN:
        break
      elif inkey == K_MINUS:
        current_string.append("_")
      elif inkey <= 127:
        current_string.append(chr(inkey))
      elif inkey == K_ESCAPE:
        exit()
      self.display_box(screen, question+ string.join(current_string,""))
    return string.join(current_string,"")

  def main(self,pergunta):
    pygame.init()
    screen = pygame.display.set_mode((800, 800))
    pygame.display.flip()
    imagemFundo = "bg_escolha.jpg"
  
    imagemBackground = pygame.image.load(imagemFundo).convert()
    
    
    screen.blit(imagemBackground, (0, 0))

    
    resposta = self.ask(screen, pergunta)
    return resposta
      
      


